﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Org.Kaka.CsmsUtil.DataEI.Import;


namespace test
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window,Org.Kaka.CsmsUtil.DataEI.Base.IDataSources
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            try
            {               

                ExcelHelper ExcelHelper = new ExcelHelper();               
                ExcelHelper.StrConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=C:\\Documents and Settings\\Administrator\\桌面\\colume.xls;Extended Properties=Excel 8.0;";
                ExcelHelper.SheetName = "iprice_pt_colume";
                dataGrid1.AutoGenerateColumns = true;
                dataGrid1.ItemsSource = ExcelHelper.GetExcelDS().Tables[0].DefaultView;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        #region 实现 IDataSources接口
        public string GetDSPuth()
        {
            throw new NotImplementedException();
        }

        public Org.Kaka.CsmsUtil.DataEI.Base.DataSourcesType GetDSType()
        {
            return Org.Kaka.CsmsUtil.DataEI.Base.DataSourcesType.EXCEL;
        }

        public string GetXMLTemplatePuth()
        {
            return @"C:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects\Export\test\XmlTemplate\Import.xml";
        }

        #endregion

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ExcelImport import = new ExcelImport();
                System.Xml.XmlDocument xmldoc = import.LoadXmlTemplate(this);
                TreeViewItem xmlNodeItem = new TreeViewItem();
                xmlNodeItem.Header = "验证模板XML结构树";
                CreatNode(xmlNodeItem, xmldoc.ChildNodes[1]);

                xmltree.Items.Add(xmlNodeItem);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void CreatNode( TreeViewItem item,System.Xml.XmlNode node)
        {
            TreeViewItem newitem = new TreeViewItem();
            newitem.Header = node.Name;
            newitem.Header = node.Attributes["HeaderText"] == null ? node.Name : node.Attributes["HeaderText"].Value;
            item.Items.Add(newitem);
            foreach (System.Xml.XmlNode n in node.ChildNodes)
            {
                CreatNode(newitem, n);
            }
        }
    }
}
